# -*- coding: utf-8 -*-
import time,datetime,os,traceback
import subprocess

def isRunning(process_name) :
    try:
        print('tasklist | findstr '+process_name)
        process=len(os.popen('tasklist | findstr '+process_name).readlines())
        print(process)
        if process >=1 :
            return True
        else:
            return False
    except:
        # print("程序错误")
        return False

if __name__=="__main__":
    flag=True
    while flag:
        currtime = datetime.datetime.now()
        currtime = currtime.strftime('%Y-%m-%d %H:%M:%S')  
        flag2 = isRunning("https_login.exe")
        
        if not flag2:
            print(currtime,'--程序未启动--',flag2)
            
            try:
                os.chdir("D:\KBCODE\selenium_crawling\dist")
                main = 'https_login.exe'
                os.system(main)
            except:
                traceback.print_exc()
            
            time.sleep(60*10)##每隔10分钟进行检查
            flag = False
        else:
            print(currtime,'--程序在运行--',flag2)
            # time.sleep(60)##每隔60s进行检查
            flag = False